import Vue from "vue";
import VueRouter from "vue-router";

// 1.安装插件
Vue.use(VueRouter);

// 导入需要使用路由切换展示的组件
import Home from "../views/home/Home.vue";
import Cart from "../views/cart/Cart.vue";
import Category from "../views/category/Category.vue";
import Profile from "../views/profile/Profile.vue";
import Detail from "../views/detail/Detail.vue";

// 2.创建路由对象
const router = new VueRouter({
  mode: "history",
  // 在routes 数组中，声明路由的匹配规则
  // path 表示匹配的哈希地址，component 表示要展示的组件
  routes: [
    // 重定向
    { path: "", redirect: "/home" },
    { path: "/home", component: Home },
    { path: "/cart", component: Cart },
    { path: "/category", component: Category },
    { path: "/profile", component: Profile },
    {
      path: "/detail/:iid",
      component: Detail,
      meta: {
        keepAlive: false,
      },
    },
  ],
});

// 3.导出
export default router;
